package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.mapper.SystemDictionaryItemMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {
    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;
    @Override
    public void save(SystemDictionaryItem systemDictionaryItem) {
        if(systemDictionaryItem.getSequence() == null){
            int max = systemDictionaryItemMapper.selectForMaxSequence(systemDictionaryItem.getParentId());
            systemDictionaryItem.setSequence(max + 1);
        }
        systemDictionaryItemMapper.insert(systemDictionaryItem);
    }

    @Override
    public void delete(Long id) {
        systemDictionaryItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(SystemDictionaryItem systemDictionaryItem) {
        systemDictionaryItemMapper.updateByPrimaryKey(systemDictionaryItem);
    }

    @Override
    public SystemDictionaryItem get(Long id) {
        return systemDictionaryItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SystemDictionaryItem> list() {
        return systemDictionaryItemMapper.selectAll();
    }

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"sequence asc");
        List<SystemDictionaryItem> list = systemDictionaryItemMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public List<SystemDictionaryItem> selectBySystemDictionaryJob() {
        return systemDictionaryItemMapper.selectBySystemDictionaryJob();
    }
    @Override
    public List<SystemDictionaryItem> selectBySystemDictionarySource() {
        return systemDictionaryItemMapper.selectBySystemDictionarySource();
    }
    @Override
    public List<SystemDictionaryItem> selectBySystemDictionaryIntentionDegree() {
        return systemDictionaryItemMapper.selectBySystemDictionaryIntentionDegree();
    }

    @Override
    public List<SystemDictionaryItem> selectBySystemDictionaryCommunicationMethod() {
        return systemDictionaryItemMapper.selectBySystemDictionaryCommunicationMethod();
    }

    @Override
    public List<SystemDictionaryItem> selectBySystemDictionarySubject() {
        return systemDictionaryItemMapper.selectBySystemDictionarySubject();
    }


}
